package com.liao.furns.web; /**
 * @author lzp
 * @version 1.0
 * lzpnb!
 */

import com.liao.furns.pojo.Member;
import com.liao.furns.service.MemberService;
import com.liao.furns.service.impl.MemberServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    MemberService memberService = new MemberServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        Member member = new Member(null, username, password, null);
        if(memberService.login(member) != null){
            request.getRequestDispatcher("/views/member/login_ok.jsp").forward(request,response);
        }else {
            request.setAttribute("username",member.getUsername());
            request.setAttribute("nameorpwderror","用户名或密码错误");
            request.getRequestDispatcher("/views/member/login.jsp").forward(request,response);
        }
    }
}
